import 'package:daoyi_ui_admin_getx/app/widgets/common_image_widget.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';

import 'info_data.dart';

final networkUriRef = RegExp("^https?://");
final localUriRef = RegExp("^/");

class InfoItemWidget extends StatelessWidget {
  final InfoItem data;

  const InfoItemWidget(this.data, {super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(10),
      margin: const EdgeInsets.only(
        bottom: 10,
      ),
      decoration: const BoxDecoration(
        color: Colors.white,
      ),
      height: 100,
      child: GestureDetector(
        onTap: () {
          if (networkUriRef.hasMatch(data.navigateUri)) {
            launchUrl(
              Uri.parse(data.navigateUri),
              mode: LaunchMode.platformDefault,
            );
          }
          if (localUriRef.hasMatch(data.navigateUri)) {
            Get.toNamed(data.navigateUri);
          }
        },
        child: Row(
          children: <Widget>[
            CommonImageWidget(
              data.imageUri,
              width: 120,
              height: 90,
            ),
            const Padding(
              padding: EdgeInsets.only(
                left: 10,
              ),
            ),
            Expanded(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Text(
                    data.title,
                    maxLines: 2,
                    overflow: TextOverflow.ellipsis,
                    style: const TextStyle(
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Text(
                        data.source,
                        style: const TextStyle(
                          color: Colors.black45,
                        ),
                      ),
                      Text(
                        data.time,
                        style: const TextStyle(
                          color: Colors.black45,
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
